import React, { Component } from "react";
import axios from "axios";

export default class App extends Component {
  getStudentInfo = () => {
    axios({
      method: "GET",
      url: "http://localhost:3000/api1/students",
    })
      .then((res) => {
        console.log(res.data);
      })
      .catch((err) => {
        console.log(err);
      });
  };

  getCarInfo = () => {
    axios({
      method: "GET",
      url: "http://localhost:3000/api2/cars",
    })
      .then((res) => {
        console.log(res.data);
      })
      .catch((err) => {
        console.log(err);
      });
  };

  render() {
    return (
      <>
        <button onClick={this.getStudentInfo}>点我获取学生数据</button>
        <button onClick={this.getCarInfo}>点我获取汽车数据</button>
      </>
    );
  }
}
